
$.formatString = function (str) {
    for (var i = 0; i < arguments.length - 1; i++) {
        str = str.replace("{" + i + "}", arguments[i + 1]);
    }
    return str;
}

function show(msg){
    $.messager.show({
        title:'系统提示',
        msg:msg,
        timeout:1000,
        showType:'show'
    });
}

function save(url,msg){
    $("#fm").form("submit",{
        url:url,
        method:'post',
        onSubmit:function(){
            return $(this).form("validate");
        },
        success:function(result){
            var result=eval('('+result+')');
            if(result.success){
                $.messager.show({
                    title: '系统提示',
                    msg: msg,
                    timeout: 3000,
                    showType: 'show'
                });
                resetValue();
                $("#dlg").dialog("close");
                $("#dg").datagrid("reload");
            }else{
                $.messager.show({
                    title:'系统提示',
                    msg:result.info,
                    timeout:1000,
                    showType:'show'
                });
            }
        }
    });
}

function closeDialog(dlgId){
    $(dlgId).dialog("close");
    resetValue();
}

function deleteData(url,Eid,id,msg){
    $.messager.confirm("系统提示","您确定要删除这条数据吗?",function(r){
        if(r){
            $.post(url,{Eid:id},function(result){
                if(result.success){
                    $.messager.show({
                        title:'系统提示',
                        msg:msg,
                        timeout:3000,
                        showType:'show'
                    });
                    $("#dg").datagrid("reload");
                }else{
                    $.messager.show({
                        title:'系统提示',
                        msg:result.info,
                        timeout:1000,
                        showType:'show'
                    });
                }
            },"json");
        }
    });
}

function authentication(url,index){
    $("#dg").datagrid('selectRow',index);
    $.messager.confirm("系统提示","您确定要认证这条数据吗?",function(r){
        if(r){
            $.post(url,{id:index},function(result){
                if(result.success){
                    $.messager.show({
                        title:'系统提示',
                        msg:'数据已认证成功！',
                        timeout:3000,
                        showType:'show'
                    });
                    $("#dg").datagrid("reload");
                }else{
                    $.messager.show({
                        title:'系统提示',
                        msg:result.info,
                        timeout:1000,
                        showType:'show'
                    });
                }
            },"json");
        }
    });
}